package com.matt.foundation.sqlOperator;


import java.sql.*;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/7/7
 * *******************************
 */
public class LiveRoomOperator {
    public static void main(String[] args) throws Exception {
//        processLiveRoom();
    }

    public static void processLiveRoom() {
        int num = 0;
        String remoteUrl = "jdbc:mysql://rm-bp1xxa9jd5ajt2km8o.mysql.rds.aliyuncs.com:3306/vega";
        String remoteName = "matt";
        String remotePWd = "HgY5CcO4";

//        String localUrl = "jdbc:mysql://localhost:3306/vega";
//        String localName = "root";
//        String localPWd = "123456";
        try {
            Class.forName("com.mysql.jdbc.Driver");

            Connection remoteConn = DriverManager.getConnection(remoteUrl, remoteName, remotePWd);
            PreparedStatement remotePreparedStatement = null;
            ResultSet remoteResultSet = null;
            String query = "select * from liveRoom";

            remotePreparedStatement = remoteConn.prepareStatement(query);

            remoteResultSet = remotePreparedStatement.executeQuery();
//            Connection localConn = DriverManager.getConnection(localUrl, localName, localPWd);
//            PreparedStatement localPreparedStatement = null;
//            ResultSet localResultSet = null;
            while (remoteResultSet.next()) {
                String id = remoteResultSet.getString(1); //id
                String name = remoteResultSet.getString(2); //名称
                String url = remoteResultSet.getString(3); //直播地址

//                Integer month = rs.getInt(16);//月份
                System.out.println("id :" + id);
                System.out.println("name :" + name);
                System.out.println("url :" + url);
                System.out.println("thumbUrl :" + url.replace("rtmp://", "http://").replace("/live","").concat(".hd.jpg"));
//                System.out.println("month :" + month);


                String update = "update liveRoom set HDUrl=?, thumbUrl=?, type=? , yingshiId=?, active=true where id=?";
////
                remotePreparedStatement = remoteConn.prepareStatement(update);
////
                remotePreparedStatement.setString(1, url + ".hd");
                remotePreparedStatement.setString(2, url.replace("rtmp://", "http://").replace("/live","").concat(".hd.jpg"));
                remotePreparedStatement.setInt(3, 1);
                String [] strs = url.split("/");
                remotePreparedStatement.setString(4, strs[strs.length-1]);
                remotePreparedStatement.setString(5, id);
                remotePreparedStatement.execute();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
